<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('FTP日志列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								配置名称：<input type="text" name="configName"/>
							</li>
							<li>
								FTP服务器IP：<input type="text" name="serverIp"/>
							</li>
							<li>
								FTP账号：<input type="text" name="ftpName"/>
							</li>
							<li class="select-time">
								<label>创建时间： </label>
								<input type="text" class="time-input" id="beginTime" placeholder="开始时间" name="params[beginTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
							</li>
							<li>
								传输状态：<select name="status">
								<option value="">所有</option>
								<option value="0">成功</option>
								<option value="1">失败</option>
							</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:record:export">
					<i class="fa fa-download"></i> 导出
				</a>
			</div>
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" style="height: 100px"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "system/record";

		$(function() {
		    var options = {
		        url: prefix + "/list",
                exportUrl: prefix + "/export",
		        modalName: "FTP推送日志",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'configName',
		            title: '配置名称（备注）'
		        },
		        {
		            field: 'serverIp',
		            title: 'FTP服务器IP'
		        },
				{
					field: 'ftpName',
					title: 'FTP账号'
				},
				{
					field: 'ftpDir',
					title: 'ftp文件目录'
				},
				{
					field: 'resourcePath',
					title: '源数据资源地址'
				},
				{
					field: 'cause',
					title: '失败原因'
				},
				{
					field: 'reply',
					title: '第三方接口返回'
				},
				{
					field: 'status',
					title: '传输状态',
					formatter: function(value, row, index) {
						var actions = [];
						if(value=="推送中") {
							return "<div style='color: #d3d300'>"+value+"</div>"
						}
						if(value=="已重新将文件转移至下载单管理"){
							return "<div style='color: #d3d300'>"+value+"</div>"
						}
						if(value=="成功") {
							return "<div style='color: #18ce11'>"+value+"</div>"
						}
						if(value == "失败"){
								actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="sdts(\'' + row.id + '\')"><i class="fa fa-chain"></i>失败，重新推送</a>');
							return actions;
							//return "<div style='color: #ff0026'>"+value+"</div>"
						}
						return value;

					}
				},
					{
						field: 'createTime',
						title: '创建时间',
						formatter: function(value, row, index) {
							// 创建一个Date对象
							const date = new Date(value);

							// 提取年、月、日、小时、分钟和秒
							const year = date.getFullYear();
							const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从0开始，需要加1
							const day = date.getDate().toString().padStart(2, '0');
							const hours = date.getHours().toString().padStart(2, '0');
							const minutes = date.getMinutes().toString().padStart(2, '0');
							const seconds = date.getSeconds().toString().padStart(2, '0');

							// 组合成格式化的字符串
							return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
						}
					}]
			};
			$.table.init(options);
		});

		/**
		 * 手动推送
		 */
		function sdts(id){
			//$.modal.msgWarning("正在开发中。。。。");
			$.post(prefix+"/sdts",{id:id},function (e){
				console.log(e)
				$.modal.alertWarning(e.msg)
				$.table.refresh();
			})
		}
	</script>
</body>
</html>